(function() {
    /*
     * 判断obj是否为一个整数
     */
    function isInteger(obj) {
        return Math.floor(obj) === obj
    }

    /*
     * 将一个浮点数转成整数，返回整数和倍数。如 3.14 >> 314，倍数是 100
     * @param floatNum {number} 小数
     * @return {object}
     *   {times:100, num: 314}
     */
    function toInteger(floatNum) {
        var ret = { times: 1, num: 0 }
        var isNegative = floatNum < 0
        if (isInteger(floatNum)) {
            ret.num = floatNum
            return ret
        }
        var strfi = floatNum + ''
        var dotPos = strfi.indexOf('.')
        var len = strfi.substr(dotPos + 1).length
        var times = Math.pow(10, len)
        var intNum = parseInt(Math.abs(floatNum) * times + 0.5, 10)
        ret.times = times
        if (isNegative) {
            intNum = -intNum
        }
        ret.num = intNum
        return ret
    }

    /*
     * 核心方法，实现加减乘除运算，确保不丢失精度
     * 思路：把小数放大为整数（乘），进行算术运算，再缩小为小数（除）
     *
     * @param a {number} 运算数1
     * @param b {number} 运算数2
     * @param digits {number} 精度，保留的小数点数，比如 2, 即保留为两位小数
     * @param op {string} 运算类型，有加减乘除（add/subtract/multiply/divide）
     *
     */
    function operation(a, b, digits, op) {
        var o1 = toInteger(a)
        var o2 = toInteger(b)
        var n1 = o1.num
        var n2 = o2.num
        var t1 = o1.times
        var t2 = o2.times
        var max = t1 > t2 ? t1 : t2
        var result = null
        switch (op) {
            case 'add':
                if (t1 === t2) { // 两个小数位数相同
                    result = n1 + n2
                } else if (t1 > t2) { // o1 小数位 大于 o2
                    result = n1 + n2 * (t1 / t2)
                } else { // o1 小数位 小于 o2
                    result = n1 * (t2 / t1) + n2
                }
                return (result / max);
            case 'subtract':
                if (t1 === t2) {
                    result = n1 - n2
                } else if (t1 > t2) {
                    result = n1 - n2 * (t1 / t2)
                } else {
                    result = n1 * (t2 / t1) - n2
                }
                return (result / max);
            case 'multiply':
                result = (n1 * n2) / (t1 * t2)
                return result;
            case 'divide':
                result = (n1 / n2) * (t2 / t1)
                return result;
        }
    }

    var utils = {}
    /**
     * [stringFomat 字符串格式化]
     * @type {Object}
     */
    utils.stringFomat = {
        /**
         * [camelcaseToHyphen 驼峰转化成-连接]
         * @param  {[type]} str [驼峰字符串]
         * @return {[type]}     [连接-字符串]
         */
        camelcaseToHyphen:function(str) {
            return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
        },
        /**
         * [numToCard 转化成卡号]
         * @param  {[type]} string [description]
         * @return {[type]}        [description]
         */
        numToCard:function(string) {
            return string.replace(/(\d{4})(?=\d)/g, "$1" + " ")
        },
        /**
         * [cardToNum 卡号转化成字符串]
         * @param  {[type]} string [description]
         * @return {[type]}        [description]
         */
        cardToNum:function(string) {
            return string.replace(/\s/ig, "")
        },
        /**
         * [moneyFormate 金额整数去掉.00]
         * @param  {[type]} string [description]
         * @return {[type]}        [description]
         */
        moneyFormate:function(string) {
            var oArray = string.split(".");
            if (oArray.length == 2) {
                if (oArray[1] > 0) {
                    return string;
                } else {
                    return oArray[0];
                }
            }
            return string;
        }

    }
    /**
     * [dateFormat 时间格式化处理]
     * @type {Object}
     */
    utils.dateFormat = {
        /**
         * [format description]
         * @param  {[Date]} date [需要格式的对象]
         * @param  {[String]} fmt  [例子：yyyy-MM-dd hh:mm:ss 连接上做处理]
         * @return {[String]}      [返回fmt的时间]
         */
        format:function(date, fmt) {
            var o = {
                "M+": date.getMonth() + 1, //月份
                "d+": date.getDate(), //日
                "h+": date.getHours(), //小时
                "m+": date.getMinutes(), //分
                "s+": date.getSeconds(), //秒
                "q+": Math.floor((date.getMonth() + 3) / 3), //季度
                "S": date.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        },
        /*日期组件获取今天的日期*/
        getTodayDate:function() {
            //是否选择今天及其今天以后的日期
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth();
            var day = date.getDate();
            return new Date(year, month, day);
        },
        /*输出当前时间*/
        getOutTime:function(time){
            var currentTime = null,str = "";
            if(time){
                currentTime = this.format(new Date(),"yyyy-MM-dd");
                str = currentTime+" "+time+":00";
            }
            return str;
        },
        dateGap30:function(start, end, day) {
            //日期间隔不超过30天
            var dayTime = day ? day : 30;
            var time = dayTime * 24 * 60 * 60 * 1000,
                gaptime = 0;
            start = start.replace(/-/g, "/");
            end = end.replace(/-/g, "/");
            gaptime = Date.parse(end) - Date.parse(start);
            if (gaptime < 0 || gaptime >= time) {
                return false;
            }
            return true;
        },
        getMonthDate:function(fmt) {
            var str = "";
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var startTime = "";
            var endTime = "";
            fmt = fmt ? fmt : "";
            month = month < 10 ? ('0' + month) : month;
            startTime = year + fmt + month + fmt + "01";
            endTime = year + fmt + month + fmt + new Date(year, month, 0).getDate();
            return { "first": startTime, "last": endTime };
        },
        getWeekDate:function() {
            var startTime = "";
            var Nowdate = new Date();
            var WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
            var month = Number(WeekFirstDay.getMonth()) + 1;
            month = month < 10 ? ('0' + month) : month;
            startTime = WeekFirstDay.getFullYear() + "-" + month + "-" + WeekFirstDay.getDate();
            return { "start": startTime, "end": utils.dateFormat.format(Nowdate, "yyyy-MM-dd") };
        },
        /*1417708800000转化成2014-12-05 00:00:00
            date 类型为string*/
        formatDate4:function(date) {
            return date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2) + " " + date.substr(8, 2) + ":" + date.substr(10, 2) + ":" + date.substr(12, 2);
        },
        formatDate2:function(string,type) {
            var stringObj = [],m = "",d = "";
            if(type == 1){
                stringObj = string.split("/");
                m = stringObj[1];
                d = stringObj[2];
                return stringObj[0] + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
            }else if( type == 2){
                stringObj = string.split("-");
                m = stringObj[1];
                d = stringObj[2];
                return stringObj[0] + '/' + parseInt(m) + '/' + parseInt(d);
            }
            return "";
        },
        /*1417708800000转化成2014-12-05 00:00:00*/
        formatDate3:function(timestamp, isymd) {
            if (timestamp) {
                var date = new Date(timestamp);
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours();
                var mi = date.getMinutes();
                var s = date.getSeconds();
                if (!isymd) { //是否年月日
                    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' ' + (h < 10 ? ('0' + h) : h) + ':' + (mi < 10 ? ('0' + mi) : mi) + ':' + (s < 10 ? ('0' + s) : s);
                } else {
                    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
                }

            } else
                return;
        },
        //2016-07-22 to Date
        stringToDate:function(string) {
            var stringObj = string.split("-");
            return new Date(stringObj[0], (parseInt(stringObj[1]) - 1), stringObj[2]);
        },
        /*19201101转换成1970-11-01 或者 19201101121212转换成1970-11-01 12:12:12*/
        dateToString:function(date,type) {
            if(type == "datebox"){
                return date.substr(0, 10);
            }else if( type == "time"){
                return date.substr(11, 5);
            }else{
                return date;
            }
        },
        datetimeToString:function(date) {
            date = date + "";
            if (date == 0) return "无";
            if (date.indexOf('-') > 0) return date;
            return date.substr(0, 4) + "." + date.substr(4, 2) + "." + date.substr(6, 2);
        },
        /*192011转换成1970-11*/
        monthToString:function(date) {
            if (date == 0) return "无";
            if (date.indexOf('-') > 0) return date;
            return date.substr(0, 4) + "-" + date.substr(4, 2);
        },
        /*生成当前的年月*/
        produceDate:function() {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            return year + "年" + month + "月";
        },
        /*192011转换成1970年11月*/
        monthToString2:function(date) {
            if (date == 0) return "无";
            if (date.indexOf('-') > 0) return date;
            return date.substr(0, 4) + "年" + date.substr(4, 2) + "月";
        },
        /*191441转换成19:14:41*/
        timeToString:function(time) {
            if (time == 0) return time;
            if (time.indexOf(':') > 0) return time;
            return time.substr(0, 2) + ":" + time.substr(2, 2) + ":" + time.substr(4, 2);
        },
        getNextNMonth:function(date,smonth) {
            var  str = '';
            var  nextDate = this.dateAdd("M", smonth, date);
            var nextMonth = nextDate.getMonth() + 1;
            nextMonth = nextMonth < 10 ? ('0' + nextMonth) : nextMonth;

            str = nextDate.getFullYear() + '/'+nextMonth+"/01";
            return new Date(str);
        },
        /*
         *   功能:DateAdd功能.
         *   参数:interval,字符串表达式，表示要添加的时间间隔.
         *   参数:number,数值表达式，表示要添加的时间间隔的个数.
         *   参数:date,时间对象.
         *   返回:新的时间对象.
         *   var now = new Date();
         *   var newDate = DateAdd( "d", 5, now);
         *---------------  DateAdd(interval,number,date)   -----------------
         */
        dateAdd:function(interval, number, date) {
            switch (interval) {
                case "y":
                    {
                        date.setFullYear(date.getFullYear() + number);
                        return date;
                        break;
                    }
                case "q":
                    {
                        date.setMonth(date.getMonth() + number * 3);
                        return date;
                        break;
                    }
                case "M":
                    {
                        date.setMonth(date.getMonth() + number);
                        return date;
                        break;
                    }
                case "w":
                    {
                        date.setDate(date.getDate() + number * 7);
                        return date;
                        break;
                    }
                case "d":
                    {
                        date.setDate(date.getDate() + number);
                        return date;
                        break;
                    }
                case "h":
                    {
                        date.setHours(date.getHours() + number);
                        return date;
                        break;
                    }
                case "m":
                    {
                        date.setMinutes(date.getMinutes() + number);
                        return date;
                        break;
                    }
                case "s":
                    {
                        date.setSeconds(date.getSeconds() + number);
                        return date;
                        break;
                    }
                default:
                    {
                        date.setDate(date.getDate() + number);
                        return date;
                        break;
                    }
            }
        }
    }
    /**
     * [Rmb description 人民币]
     * @type {Object}
     */
    utils.Rmb = {
        /**
         * [upDigit 数字金额大写转换(可以处理整数,小数,负数)]
         * @param  {[type]} n [description]
         * @return {[type]}   [description]
         */
        upDigit:function(n) {
            var fraction = ['角', '分'];
            var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
            var unit = [
                ['元', '万', '亿'],
                ['', '拾', '佰', '仟']
            ];
            var head = n < 0 ? '欠' : '';
            n = Math.abs(n);
            var s = '';
            for (var i = 0; i < fraction.length; i++) {
                s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
            }
            s = s || '整';
            n = Math.floor(n);
            for (var i = 0; i < unit[0].length && n > 0; i++) {
                var p = '';
                for (var j = 0; j < unit[1].length && n > 0; j++) {
                    p = digit[n % 10] + unit[1][j] + p;
                    n = Math.floor(n / 10);
                }
                s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
            }
            return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
        },
        /**
         * [formatRMB 格式化]
         * @param  {[muber]} money  [传入需要格式化的钱（分为单位）]
         * @param  {[string]} format [thousands：转换千分位,tenthousand:转换万元,空保留小数]
         * @return {[string]}        [返回格式化后的钱]
         */
        formatRMB:function(money, format) {
            var RMB = null;
            if (isNaN(money)) {
                RMB = 0;
            } else {
                RMB = (Number(money)).toFixed(2); //分转换成元保留两位小数
                switch (format) {
                    case "thousands":
                        RMB = (RMB + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
                        break;
                    case "tenthousand":
                        RMB = parseInt(RMB) >= 10000 ? (parseInt(RMB) / 10000) + "万" : parseInt(RMB);
                        break;
                    default:
                        RMB = RMB;
                }
            }
            return RMB
        },
        /**
         * [rmbYF 计算元与分]
         * @param  {[muber]} money [传入需要格式化的钱]
         * @return {[object]}   RMB     [存取值]
         */
        rmbYF:function(money) {
            var RMB = {};
            if (isNaN(money)) {
                RMB.YUAN = 0;
                RMB.FEN = "00";
            } else {
                var money = (Number(money) / 100).toFixed(2); //分转换成元保留两位小数
                RMB.YUAN = money.split(".")[0];
                RMB.FEN = money.split(".")[1];
            }
            return RMB
        },
        rmbToYuan:function(value){
            if (!value) {
                return "0";
            }
            return utils.floatObj.multiply(value, 0.01, 2);
        }
    };

    /**
     * [Input 输入替换]
     * @type {Object}
     */
    utils.Input = {

        clearNoPriceMax6:function(obj) {

            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2'); //保留两位小数

            var _reg = /^(.){0,6}$/;
            if (!_reg.test(obj.value)) {
                obj.value = obj.value.substr(0, 6);
                return;
            }
        },
        faceDecimal: function(str) {
            str = str.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            str = str.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            str = str.replace(/^\./g, ""); //验证第一个字符是数字而不是
            str = str.replace(/^(\d\d\d\d)(\d+).*$/, '$1');
            str = str.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            str = str.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            str = str.replace(/^(\d{1,4})\.(\d\d).*$/, '$1.$2');
            return str;
        },
        clearNoPriceMax11:function(obj) {

            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2'); //保留两位小数

            var _reg = /^(.){0,11}$/;
            if (!_reg.test(obj.value)) {
                obj.value = obj.value.substr(0, 11);
                return;
            }
        },
        clearNoPriceMax10:function(obj) {
            // console.log(obj.validity.badInput);
            // if(!obj.value){
            //     return;
            // }
            // console.log(obj.value);
            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2'); //保留两位小数

            var _reg = /^(.){0,10}$/;
            if (!_reg.test(obj.value)) {
                obj.value = obj.value.substr(0, 10);
                return;
            }
        },

        /**
         * [clearNoPrice 小数点两位]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearNoPrice:function(obj) {
            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2'); //保留两位小数
        },
        /**
         * [clearNoPrice 小数点后n位]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearPrice:function(obj, n) {
            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            if (n == 1) {
                obj.value = obj.value.replace(/^(\d+)\.(\d).*$/, '$1.$2'); //保留一个位小数
            } else if (n == 2) {
                obj.value = obj.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2'); //保留两位小数
            } else if (n == 3) {
                obj.value = obj.value.replace(/^(\d+)\.(\d\d\d).*$/, '$1.$2'); //保留三位小数
            }
        },
        /**
         * [clearSpace description]
         * @param  {[type]} obj [description]
         * @return {[type]}     [description]
         */
        clearSpace:function(obj) {
            obj.value = obj.value.replace(/\s/g, "") //清楚空格
        },
        /**
         * [clearNoInt 非0整数]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearNoInt:function(obj) {
            obj.value = obj.value.replace(/^[0]/g, "")
            obj.value = obj.value.replace(/\D/g, '');
        },
        /**
         * [clearNoInt2 整数]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearNoInt2:function(obj) {
            obj.value = obj.value.replace(/\D/g, '');
        },
        /**
         * [clearNoChinese 只能输入英文字母和数字,不能输入中文]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearNoChinese:function(obj) {
            obj.value = obj.value.replace(/[^\w\.\/]/ig, '')
        },
        /**
         * [clearNoInt 整数]
         * @param  {[Object]} obj [输入对象]
         * @return {[type]}     [description]
         */
        clearNoInteger:function(obj) {
            obj.value = obj.value.replace(/\D/g, '');
        },
        /**
         * [clearNoInt 只能输入字母和汉字]
         */
        clearNoLetterChinese:function(obj) {
            obj.value = obj.value.replace(/[^\a-\z\A-\Z\u4E00-\u9FA5]/g, '')
        },
        /**
         * [clearNoInt 只能输入字母和数字]
         */
        clearNOEN:function(str) {
            str = str.replace(/[^\a-\z\A-\Z0-9]/g, '');
            return str;
        },
        /**
         * [clearNoInt 只能输入字母,汉字和数字]
         */
        clearNoLetterChineseNumber:function(obj) {
            obj.value = obj.value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g, '')
        },
        /**
         * [clearDiscount 只能输入0.1~9.9]
         */
        clearDiscount:function(str) {
            //折扣：只能输入0.1~9.9
            str = str.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            str = str.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            str = str.replace(/^\./g, ""); //验证第一个字符是数字而不是
            str = str.replace(/^(\d\d)(\d+).*$/, '$1');
            str = str.replace(/\.{1,}/g, "."); //只保留第一个. 清除多余的
            str = str.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            str = str.replace(/^(\d{1,2})\.(\d\d).*$/, '$1.$2');
            if (parseFloat(str) > 10 && str.indexOf(".") == -1) {
                str = str.substring(0, 1);
            } else if (parseFloat(str) > 10 && str.indexOf(".") != -1) {
                str = str.substring(0, 3);
            }
            return str;
        },
        /**
         * [clearNoDiscount 只能输入0.1~9.9]
         */
        clearNoDiscount:function(str) {
            //折扣：只能输入0.1~9.9
            str = str.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            str = str.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            str = str.replace(/^\./g, ""); //验证第一个字符是数字而不是
            str = str.replace(/^(\d\d)(\d+).*$/, '$1');
            str = str.replace(/\.{1,}/g, "."); //只保留第一个. 清除多余的
            str = str.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            str = str.replace(/^(\d{1,2})\.(\d).*$/, '$1.$2');
            if (parseFloat(str) >= 10 && str.indexOf(".") == -1) {
                str = str.substring(0, 1);
            } else if (parseFloat(str) >= 10 && str.indexOf(".") != -1) {
                str = str.substring(0, 3);
            } else if (str == '0.0') {
                str = str.substring(0, 2);
            }
            return str;
        },
        clearAmount: function(obj) {
            //小数点前5位，后面2位
            obj.value = obj.value.replace(/^[0][0-9]/g, "") //清楚以0开始的非小数的字符
            obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是
            obj.value = obj.value.replace(/^(\d\d\d\d\d)(\d+).*$/, '$1');
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\d{1,5})\.(\d\d).*$/, '$1.$2');
        },
    }
    /**
     * [valid 验证类]
     * @type {Object}
     */
    utils.Valid = {
        /**
         * [isNum 是否位数字]
         * @param  {[string]}  num [description]
         * @return {Boolean}     [description]
         */
        isNum:function(num) { //# 是否为数
            return !isNaN(num);
        },
        /**
         * [isEmail description]
         * @param  {[type]}  mail [description]
         * @return {Boolean}      [description]
         */
        isEmail:function(mail) { //# 是否为 邮箱
            return /^([a-z0-9]+[_\-\.]?)*[a-z0-9]+@([a-z0-9]+[_\-\.]?)*[a-z0-9]+\.[a-z]{2,5}$/i.test(mail);
        },
        /**
         * [isFloat 浮点数]
         * @param  {[type]}  num [description]
         * @return {Boolean}     [description]
         */
        isFloat:function(num) { //# 是否为 浮点数
            return /^(([1-9]\d*)|(\d+\.\d+)|0)$/.test(num);
        },
        /**
         * [isInt 正整数]
         * @param  {[type]}  num [description]
         * @return {Boolean}     [description]
         */
        isInt:function(num) { //# 是否为 正整数
            return /^[1-9]\d*$/.test(num);
        },
        /**
         * [isLicitDeciaml 是否是合法的数字]
         * @param  {[type]}  num [description]
         * @return {Boolean}     [description]
         */
        isLicitDeciaml:function(amount) {
            if (amount > 0 && /^\d+(\.\d{1,2})?$/.test(amount)) {
                return true;
            } else {
                return false;
            }
        },
        /**
         * [isChinese 是否全为汉字]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isChinese:function(str) { //# 是否全为 汉字
            return /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])+$/gi.test(str);
        },
        /**
         * [isChinese 是否金额]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isAmount:function(str) {
            if (str == "0" || str == "0." || str == "0.0" || str == "0.00") {
                return false;
            }
            return /^([1-9][\d]{0,}|0)(\.[\d]{1,2})?$/gi.test(str);
        },
        isTimeSpinner:function(start, end) {
            var t1 = parseInt(start.replace(/:/g, ""));
            var t2 = parseInt(end.replace(/:/g, ""));
            return t1 <= t2;
        },
        isLateDay:function(start, end) {
            //晚一天比较字符串
            start = utils.dateFormat.dateAdd("d", 1, new Date(start));
            return start <= new Date(end);
        },
        /**
         * [isChinese 是否为中文名称]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isChineseName:function(str) {
            return /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0]{2,5})+([·|•]([\u4E00-\u9FA5]|[\uFE30-\uFFA0]){2,5})*$/gi.test(str);
        },
        /**
         * [isBankAccount 是否为银行账号]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isBankAccount:function(str) {
            return /^\d{8,32}$/gi.test(str);
        },
        /**
         * [isCEN  是否为中文数字英文符号]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isCENP:function(str) {
            return /^[\，\。\！\？\：\,\.\!\?\:\·\¥\%\u4E00-\u9FA5A-Za-z0-9_]+$/gi.test(str);
        },
        /**
         * [isCEN  是否为中文数字英文]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isCEN:function(str) {
            return /^[\u4E00-\u9FA5A-Za-z0-9_]+$/gi.test(str);
        },
        /**
         * [isCEN  是否为数字英文]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isEN:function(str) {
            return /^[A-Za-z0-9]+$/gi.test(str);
        },
        /**
         * [isCEN  是否为中文英文]
         * @param  {[type]}  str [description]
         * @return {Boolean}     [description]
         */
        isCE:function(str) {
            return /^[\u4E00-\u9FA5A-Za-z_]+$/gi.test(str);
        },
        //
        /**
         * [isIdCard 身份证验证]
         * @param {[type]} gets [description]
         * @return {Boolean}     [description]
         */
        isIdCard:function(gets) {
            var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; // 加权因子;
            var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2]; // 身份证验证位值，10代表X;
            if (gets.length == 15) {
                return isValidityBrithBy15IdCard(gets);
            } else if (gets.length == 18) {
                var a_idCard = gets.split(""); // 得到身份证数组
                if (isValidityBrithBy18IdCard(gets) && isTrueValidateCodeBy18IdCard(a_idCard)) {
                    return true;
                }
                return false;
            }
            return false;

            function isTrueValidateCodeBy18IdCard(a_idCard) {
                var sum = 0; // 声明加权求和变量
                if (a_idCard[17].toLowerCase() == 'x') {
                    a_idCard[17] = 10; // 将最后位为x的验证码替换为10方便后续操作
                }
                for (var i = 0; i < 17; i++) {
                    sum += Wi[i] * a_idCard[i]; // 加权求和
                }
                var valCodePosition = sum % 11; // 得到验证码所位置
                if (a_idCard[17] == ValideCode[valCodePosition]) {
                    return true;
                }
                return false;
            }

            function isValidityBrithBy18IdCard(idCard18) {
                var year = idCard18.substring(6, 10);
                var month = idCard18.substring(10, 12);
                var day = idCard18.substring(12, 14);
                var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
                // 这里用getFullYear()获取年份，避免千年虫问题
                if (temp_date.getFullYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
                    return false;
                }
                return true;
            }

            function isValidityBrithBy15IdCard(idCard15) {
                var year = idCard15.substring(6, 8);
                var month = idCard15.substring(8, 10);
                var day = idCard15.substring(10, 12);
                var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
                // 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法
                if (temp_date.getYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
                    return false;
                }
                return true;
            }
        },
        /**
         * [isMobile  手机验证]
         * @param  {[type]} gets [description]
         * @return {[type]}      [description]
         */
        isMobile:function(gets) {
            return /^1[0-9]{10}$/.test(gets);
        },
        /**
         * [isTel 验证座机]
         * @param  {[type]}  tel [description]
         * @return {Boolean}     [description]
         */
        isTel:function(tel) { //# 是否为 电话
            return /^\d{3,4}-\d{7,8}(-\d{1,6})?$/.test(tel);
        },
        /**
         * [isCustomerTel 验证客服电话]
         * @param  {[type]}  tel [description]
         * @return {Boolean}     [description]
         */
        isCustomerTel:function(tel) { //# 是否为 客服电话
            return /^[0-9\-]+$/.test(tel);
        },
        /**
         * [isDiscount 验证折扣金额]
         * @param  {[type]}  text [description]
         * @return {Boolean}     [description]
         */
        isDiscount:function(price) { //# 是否为 折扣金额
            if (price == "0" || price == "0." || price == "0.0" || price == "0.00" || /^[1-9]\d?\.$/.test(price)) {
                return false;
            }
            if (parseFloat(price) > 10.00) {
                return false;
            }
            return true;
        },
        /**
         * [isPrice校验价格和金额的方法]
         * @param  {[type]}  price [description]
         * @return {Boolean}       [description]
         */
        isPrice:function(price) {
            if (price == "0" || price == "0." || price == "0.0" || price == "0.00") {
                price = "0";
                return true;
            } else {
                var index = price.indexOf("0");
                var length = price.length;
                if (index == 0 && length > 1) { /*0开头的数字串*/
                    var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                    if (!reg.test(price)) {
                        return false;
                    } else {
                        return true;
                    }
                } else { /*非0开头的数字*/
                    var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                    if (!reg.test(price)) {
                        return false;
                    } else {
                        return true;
                    }
                }
                return false;
            }
        },
        /**
         * [isPlateNumber 车牌号验证]
         * @param  {[type]} gets [description]
         * @return {[Boolean]}      [description]
         */
        isPlateNumber:function(gets) {
            var re = /^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{5}$/; //车牌号
            if (gets.search(re) == -1) {
                return false;
            } else {
                return true;
            }
        },
        /**
         * [isName 姓名验证]
         * @param  {[type]} gets [description]
         * @return {[Boolean]}      [description]
         */
        isName:function(gets) {
            return /[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*/.test(gets);
        },
        /**
         * [passCheck 密码验证]
         * @param  {[type]} gets [description]
         * @return {[Boolean]}      [description]
         */
        passCheck:function(gets) {
            var number = 0,
                varter = 0,
                other = 0,
                regs = /^([a-zA-Z0-9!\$&'\(\)\*\+,.;:}{\/\=-@%^#~]){8,20}$/;
            for (var i = gets.length - 1; i >= 0; i--) {
                var charater = gets.charCodeAt(i);
                if (charater >= 48 && charater <= 57) {
                    //统计数字
                    number++;
                } else if ((charater >= 65 && charater <= 90) || (charater >= 97 && charater <= 122)) {
                    //统计字母
                    varter++;
                } else {
                    other++;
                }
            }
            console.log(11)
            if (number >= 1 && varter >= 1 && regs.test(gets)) {
                //密码格式为8-20位数字和字母组合
                return true;
            }
            return false;
            //return /^\d[a-zA-Z][!\$&'\(\)\*\+,.;:}{\/\=-@#~]$/; 
        },
        /**
         * [contrastDate 时间对比]
         * @param  {["YYYY--MM-DD"]} a [第一个日期]
         * @param  {["YYYY--MM-DD"]} b [第二个日期]
         * @param  {[int]} number [间隔日期天]
         * @return {[Boolean]}   [如果第一个大于第二 false  反之 true]
         */
        contrastDate:function(a, b, number) {
            var num = number ? number : 0;
            var arr = a.split("-");
            var startTime = new Date(arr[0], arr[1] - 1, arr[2]);
            var startTimes = startTime.getTime();
            var arrs = b.split("-");
            var endTime = new Date(arrs[0], arrs[1] - 1, arrs[2]);
            var endTimes = endTime.getTime();
            if (num != 0) {
                var datenum = num * 24 * 60 * 60 * 1000;
                if (startTimes + datenum >= endTimes) {
                    return true;
                } else {
                    return false;
                }
            } else {
                if (startTimes <= endTimes) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    };

    // deepCopy
    utils.deepCopyArray = function(data) {
        var o = [];
        for (var i = 0; i < data.length; i++) {
            o.push(data[i]);
        }
        return o;
    }

    // deepCopy
    utils.deepCopyArray2 = function(data) {
        var o = [];
        for (var i = 0; i < data.length; i++) {
            var newobj = {};
            for (var j in data[i]) {
                newobj[j] = data[i][j];
            }
            o.push(newobj);
        }
        return o;
    }

    // deepCopy
    utils.deepCopyArray3 = function(odata) {
        var o = {};
        for (var key in odata) {
            o[key] = [];
            for (var m = 0; m < odata[key].length; m++) {
                var item = {};
                for (var n in odata[key][m]) {
                    item[n] = odata[key][m][n];
                }
                o[key].push(item);
            }
        }
        return o;
    }

    // deepCopyParam-过滤没有值的参数
    utils.deepCopyParam = function(data) {
        var o = [];
        for (var i = 0; i < data.length; i++) {
            data[i] && o.push(data[i]);
        }
        return o;
    }

    // shallowCopyObject
    utils.shallowCopyObject = function(option) {
        var o = {};
        for (var i in option) {
            o[i] = option[i];
        }
        return o;
    }

    // deepCopy
    utils.deepCopyObject = function(option, data) {
        for (var i in option) {
            if (data[i]) {
                if (i == 'areaId') {
                    option[i] = data['publicAreaId'];
                } else if (i == 'cityId') {
                    option[i] = data['publicCityId'];
                } else {
                    option[i] = data[i];
                }
            }
        }
        return option;
    }
    // deepCopy-简单赋值对象
    utils.simpleCopyObject = function(data) {
        var option = {};
        for (var i in data) {
            if (i == 'sellerInvoiceClientList' || i == 'sellerTaxItemsList') {
                option[i] = [];
                for (var m = 0; m < data[i].length; m++) {
                    var item = {};
                    for (var n in data[i][m]) {
                        item[n] = data[i][m][n];
                    }
                    option[i].push(item);
                }
            } else {
                option[i] = data[i];
            }
        }
        return option;
    }
    // 增值业务判断
    utils.addServices = function(datas) {
        var result = {
                errors: "",
                msg: "",
            },
            todayTime = "";

        if (datas.state == 0) {
            todayTime = utils.dateFormat.format(new Date(), "hh:mm");
            if (datas.specialStartTime && datas.specialEndTime) {
                if (datas.specialStartTime <= todayTime && todayTime <= datas.specialEndTime) {
                    //通过
                    result.errors = 'VAS000';
                    result.msg = "通过";

                } else {
                    //不在服务时间
                    result.errors = 'VAS002';
                    result.msg = "抱歉，服务时间为" + datas.specialStartTime + "—" + datas.specialEndTime;
                }
            } else {
                //通过
                result.errclearNoIntors = 'VAS000';
                result.msg = "通过";
            }
        } else if (datas.state == 1) {
            //维护中
            result.errors = 'VAS003';
            result.msg = '系统维护中，给您带来不便，请谅解';
        }
        return result;
    }
    // 加减乘除的四个接口
    utils.floatObj = {
        add: function(a, b, digits) {
            return operation(a, b, digits, 'add')
        },
        subtract: function(a, b, digits) {
            return operation(a, b, digits, 'subtract')
        },
        multiply: function(a, b, digits) {
            return operation(a, b, digits, 'multiply')
        },
        divide: function(a, b, digits) {
            return operation(a, b, digits, 'divide')
        }
    }


    //计算距离(进行经纬度转换为距离的计算)，参数分别为第一点的纬度，经度；第二点的纬度，经度
    utils.getDistance = function(lat1, lng1, lat2, lng2) {
        function Rad(d) {
            return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
        }
        var radLat1 = Rad(lat1);
        var radLat2 = Rad(lat2);
        var a = radLat1 - radLat2;
        var b = Rad(lng1) - Rad(lng2);
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
            Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378.137; // EARTH_RADIUS;
        //s = Math.round(s * 1000); //输出为米
        // s = Math.round(s * 1000) / 1000; //输出为千米
        s = s * 1000;
        return s;
    }

    //组合省市区的数据
    utils.combineAddress = function(odata) {
        var provinceList = [],
            cityObj = {},
            areaObj = {};

        for (var i = 0; i < odata.length; i++) {
            var nCity = [];
            provinceList.push({ "text": odata[i].name, "value": odata[i].code });
            if (odata[i].areaList) {
                for (var m = 0; m < odata[i].areaList.length; m++) {
                    var nArea = [];
                    nCity.push({ "text": odata[i].areaList[m].name, "value": odata[i].areaList[m].code });
                    if (odata[i].areaList[m].areaList) {
                        for (var n = 0; n < odata[i].areaList[m].areaList.length; n++) {
                            nArea.push({ "text": odata[i].areaList[m].areaList[n].name, "value": odata[i].areaList[m].areaList[n].code });
                        }
                    }
                    areaObj[odata[i].areaList[m].code] = nArea;
                }
            }
            cityObj[odata[i].code] = nCity;
        }
        return { "province": provinceList, "city": cityObj, "district": areaObj, };
    }
    window.utils = utils;
})();